HOST=arm-linux-gnueabihf-
ROOT_DIR = /home/vmuser/work/new/anet-iot

CC = $(HOST)gcc
AR = $(HOST)ar

CFLAGS = -I$(ROOT_DIR)/include/ -L$(ROOT_DIR)/public/
LDFLAGS = -lpthread -ldl -lrt -lm -lpaho-mqtt3c
EXEPATH = $(ROOT_DIR)/install/
COMM = $(ROOT_DIR)/include/common.h

COREPATH = $(ROOT_DIR)/core
PLUGINPATH1 = $(ROOT_DIR)/protocol/coll/ModbusHost_RTU_Addr
PLUGINPATH2 = $(ROOT_DIR)/protocol/trans/Acrel_EIOT
PLUGINPATH3 = $(ROOT_DIR)/protocol/trans/AWT-IOT

PORTPATH = $(ROOT_DIR)/public/port
UTILSPATH = $(ROOT_DIR)/public/utils
MODBUSPATH = $(ROOT_DIR)/public/libmodbus


TARGET = ./obj/AWT200

SRC = $(wildcard $(COREPATH)/*.c) $(wildcard $(PLUGINPATH1)/*.c) $(wildcard $(PLUGINPATH2)/*.c) $(wildcard $(PLUGINPATH3)/*.c) $(wildcard $(PORTPATH)/*.c) $(wildcard $(UTILSPATH)/*.c) $(wildcard $(MODBUSPATH)/*.c)
OBJS = $(patsubst %.c,./obj/%.o,$(notdir $(SRC))) 

$(TARGET):$(OBJS)
	$(CC) $(CFLAGS) -fPIC -o $(TARGET) $(OBJS) $(LDFLAGS)
	cp $(TARGET) ./

obj/%.o:$(COREPATH)/%.c $(COMM)
	$(CC) $(CFLAGS) -fPIC -c $< -o $@
	
obj/%.o:$(PLUGINPATH1)/%.c $(COMM)
	$(CC) $(CFLAGS) -fPIC -c $< -o $@

obj/%.o:$(PLUGINPATH2)/%.c $(COMM)
	$(CC) $(CFLAGS) -fPIC -c $< -o $@

obj/%.o:$(PLUGINPATH3)/%.c $(COMM)
	$(CC) $(CFLAGS) -fPIC -c $< -o $@

obj/%.o:$(PORTPATH)/%.c
	$(CC) $(CFLAGS) -fPIC -c $< -o $@

obj/%.o:$(UTILSPATH)/%.c
	$(CC) $(CFLAGS) -fPIC -c $< -o $@

obj/%.o:$(MODBUSPATH)/%.c
	$(CC) $(CFLAGS) -fPIC -c $< -o $@

.PHYONY: clean
clean:
	-rm -f ./obj/*
	-rm AWT200
